{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Video-RAG using Ragie\n",
    "\n",
    "This notebook demonstrates how to build a video-based Retrieval Augmented Generation (RAG) system. It uses [Ragie's](https://www.ragie.ai/) video ingestion and retrieval capabilities to enable semantic search and Q&A over video content."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "import time\n",
    "\n",
    "from dotenv import load_dotenv\n",
    "from ragie import Ragie\n",
    "\n",
    "load_dotenv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "ragie = Ragie(\n",
    "    auth=os.getenv('RAGIE_API_KEY')\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Remove previous data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = ragie.documents.list()       \n",
    "documents = response.result.documents\n",
    "\n",
    "for document in documents:\n",
    "    try:\n",
    "        ragie.documents.delete(\n",
    "            document_id=document.id\n",
    "        )\n",
    "        print(f\"Deleted document {document.id}\")\n",
    "    except Exception as e:\n",
    "        print(f\"Error deleting document {document.id}: {e}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ingestion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "status='partitioning' id='e80b5e34-ba44-4e88-a627-bc2199e350c2' created_at=datetime.datetime(2025, 6, 13, 10, 44, 38, 394269, tzinfo=TzInfo(UTC)) updated_at=datetime.datetime(2025, 6, 13, 10, 44, 39, 24620, tzinfo=TzInfo(UTC)) name='messi-goals.mp4' metadata={} partition='default' chunk_count=None external_id=None page_count=None\n"
     ]
    }
   ],
   "source": [
    "current_dir = os.path.curdir\n",
    "file_path = os.path.join(current_dir, 'videos/messi-goals.mp4')\n",
    "result = ragie.documents.create(request={\n",
    "    \"file\": {\n",
    "        \"file_name\": \"messi-goals.mp4\",\n",
    "        \"content\": open(file_path, \"rb\"),\n",
    "    },\n",
    "    \"mode\": {\n",
    "        \"video\": \"audio_video\"\n",
    "    }\n",
    "})\n",
    "\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Retrieval"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "scored_chunks=[ScoredChunk(text='{\"video_description\": \"Okay, here\\'s a detailed description of the video:\\\\n\\\\n**Overall Impression:**\\\\n\\\\nThe video focuses on a tense moment from a football (soccer) match. It starts with a game highlight and transitions into promotional content.\\\\n\\\\n**Visual Breakdown:**\\\\n\\\\n*   **0:00-0:06:** A game clip shows an intense moment near the goal.\\\\n    *   The camera focuses on the goal area in a packed stadium.\\\\n    *   The score is ARG 2-2 FRA at 107:55 in the game.\\\\n    *   A player shoots, the goalkeeper blocks but deflects the ball. Another player then shoots in the rebound attempt.\\\\n    *   There is audible cheering and excitement from the crowd.\\\\n\\\\n*   **0:07-0:15:** Advertisement/Promotional content:\\\\n    *   The background transitions to a deep blue colour.\\\\n    *   The following text overlays are displayed in white: \\\\\"THE ACTION IS ONLY JUST KICKING OFF\\\\\", \\\\\"ONLY A\\\\\", \\\\\"FIFA\\\\\", \\\\\"STREAMING THE FREE STREAMING PLATFORM\\\\\".\\\\n    *   Flashes of popular football players are shown briefly: Lionel Messi and Christiano Ronaldo.\\\\n\\\\n**Key Observations:**\\\\n\\\\n*   The video emphasizes a dramatic moment in football, likely a decisive goal or near-miss, to grab attention.\\\\n*   The text and graphics suggest an advertisement for a FIFA streaming service.\\\\n*   The use of Messi and Ronaldo enhances the promotional value.\\\\n\\\\nIn essence, the video captures the drama of a football match and promotes the FIFA streaming platform.\", \"audio_transcript\": \"\"}', score=0.1, id='445466eb-85f7-4d25-becc-5eb89f13bb0c', index=8, document_id='e80b5e34-ba44-4e88-a627-bc2199e350c2', document_name='messi-goals.mp4', document_metadata={}, links={'self': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/445466eb-85f7-4d25-becc-5eb89f13bb0c', type='application/json'), 'self_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/445466eb-85f7-4d25-becc-5eb89f13bb0c/content?media_type=text/plain-text', type='text/plain-text'), 'document': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2', type='application/json'), 'document_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=text/plain-text', type='text/plain-text'), 'self_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/445466eb-85f7-4d25-becc-5eb89f13bb0c/content?media_type=audio/mpeg', type='audio/mpeg'), 'self_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/445466eb-85f7-4d25-becc-5eb89f13bb0c/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'document_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg', type='audio/mpeg'), 'document_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'self_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/445466eb-85f7-4d25-becc-5eb89f13bb0c/content?media_type=video/mp4', type='video/mp4'), 'self_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/445466eb-85f7-4d25-becc-5eb89f13bb0c/content?media_type=video/mp4&download=true', type='video/mp4'), 'document_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4', type='video/mp4'), 'document_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4&download=true', type='video/mp4')}, metadata={'end_time': 135.0, 'start_time': 120.0}), ScoredChunk(text='{\"video_description\": \"Of course! Here\\'s a detailed description of the video you provided:\\\\n\\\\n**Overall Impression:**\\\\n\\\\nThe video captures a significant moment in a soccer match, specifically a penalty kick taken and scored by Lionel Messi, playing for Argentina. The excitement of the crowd is palpable, and the focus is intensely on Messi and the action around the goal.\\\\n\\\\n**Detailed Breakdown:**\\\\n\\\\n1.  **Initial Focus:** The video begins with a close-up of Lionel Messi\\'s face. His expression is focused and intense. The camera is at about his eye level.\\\\n2.  **The Kick:** As the game action begins, the shot widens to show Messi setting up for a penalty kick. The camera provides a wide shot of the field, including the goal, the goalkeeper from Saudi Arabia, and other players from both teams forming lines near the goal.\\\\n3.  **Goal Scored:** Messi strikes the ball. The goalkeeper dives but is too late. The ball goes into the net. The crowd erupts in cheers.\\\\n4.  **Celebration:** The camera follows Messi as he celebrates, running towards his teammates. They surround him in a joyful huddle. The Argentine team celebrates their goal together.\\\\n5.  **Goal Replay:** A quick cut back to the goal area shows a close-up of the goal being scored and the goalkeeper\\'s failed attempt to block it. It highlights the precision and placement of Messi\\'s penalty kick.\\\\n\\\\n**Key Elements:**\\\\n\\\\n*   **Messi as the Focus:** Lionel Messi is clearly the central figure, with the camera prioritizing his expressions and actions.\\\\n*   **Crowd Enthusiasm:** The loud cheering and visible excitement in the crowd emphasizes the importance of the moment.\\\\n*   **The Goal Itself:** The video focuses on both the shot itself and the replay, which highlights the skill of the player and the moment of success.\\\\n*   **Team Spirit:** The celebration shows the unity and camaraderie of the Argentine team.\\\\n\\\\n**In conclusion, the video captures a thrilling moment in a high-stakes soccer match, highlighting Messi\\'s skill and the electrifying atmosphere of the game.**\", \"audio_transcript\": \"\"}', score=0.09090909090909091, id='9e8cd78b-aa96-4d8a-95bc-8f2f46cf7b6c', index=0, document_id='e80b5e34-ba44-4e88-a627-bc2199e350c2', document_name='messi-goals.mp4', document_metadata={}, links={'self': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/9e8cd78b-aa96-4d8a-95bc-8f2f46cf7b6c', type='application/json'), 'self_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/9e8cd78b-aa96-4d8a-95bc-8f2f46cf7b6c/content?media_type=text/plain-text', type='text/plain-text'), 'document': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2', type='application/json'), 'document_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=text/plain-text', type='text/plain-text'), 'self_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/9e8cd78b-aa96-4d8a-95bc-8f2f46cf7b6c/content?media_type=audio/mpeg', type='audio/mpeg'), 'self_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/9e8cd78b-aa96-4d8a-95bc-8f2f46cf7b6c/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'document_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg', type='audio/mpeg'), 'document_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'self_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/9e8cd78b-aa96-4d8a-95bc-8f2f46cf7b6c/content?media_type=video/mp4', type='video/mp4'), 'self_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/9e8cd78b-aa96-4d8a-95bc-8f2f46cf7b6c/content?media_type=video/mp4&download=true', type='video/mp4'), 'document_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4', type='video/mp4'), 'document_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4&download=true', type='video/mp4')}, metadata={'end_time': 15.0, 'start_time': 0.0}), ScoredChunk(text='{\"video_description\": \"Here is a detailed description of the video:\\\\n\\\\n**Visuals:**\\\\n\\\\n*   **Opening Scene:** The video starts with a close-up of several soccer players, wearing the light blue and white jersey of Argentina, in a celebratory hug. They are in the midst of a crowd, suggesting a significant moment in the game. The upper left of the screen shows a game status display: \\\\\"63:38 ARG 1-0 MEX.\\\\\" The \\\\\"FIFA+\\\\\" logo is in the upper right corner.\\\\n*   **Celebration Details:** The players are highly animated, with faces of intense excitement and shouts of joy. The camera focuses on the embrace of players.\\\\n*   **Goal Replay:** A replay follows, displaying the soccer ball entering the net. It shows an Argentinian player, number 10 (Lionel Messi), kicking a low shot towards the goal. The Mexican goalkeeper, in a red and blue uniform, is seen diving in an attempt to block the shot but fails.\\\\n*   **Wide Shot of the Stadium:** A wider angle shows the goal from behind the net, giving a view of the vast stadium, full of spectators. The lighting is bright and the pitch is green.\\\\n*   **Focus on the Goalkeeper:** The camera then centers on the Mexican goalkeeper, lying on the ground after the ball has already passed him and made its way into the goal.\\\\n\\\\n**Overall Impression:**\\\\n\\\\nThe video captures a triumphant moment in a soccer match: Argentina scores a goal against Mexico. It showcases the emotional celebration of the Argentinian team. The replay allows the viewer to see how the goal was scored, highlighting the skill of Lionel Messi and the attempt made by the Mexican goalkeeper. The camera angles switch between close-ups of the players and wider shots of the stadium, immersing the viewer in the atmosphere of the game.\", \"audio_transcript\": \"\"}', score=0.08333333333333333, id='7a46ff16-422b-4ac8-8302-ae369fa723d6', index=2, document_id='e80b5e34-ba44-4e88-a627-bc2199e350c2', document_name='messi-goals.mp4', document_metadata={}, links={'self': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/7a46ff16-422b-4ac8-8302-ae369fa723d6', type='application/json'), 'self_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/7a46ff16-422b-4ac8-8302-ae369fa723d6/content?media_type=text/plain-text', type='text/plain-text'), 'document': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2', type='application/json'), 'document_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=text/plain-text', type='text/plain-text'), 'self_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/7a46ff16-422b-4ac8-8302-ae369fa723d6/content?media_type=audio/mpeg', type='audio/mpeg'), 'self_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/7a46ff16-422b-4ac8-8302-ae369fa723d6/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'document_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg', type='audio/mpeg'), 'document_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'self_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/7a46ff16-422b-4ac8-8302-ae369fa723d6/content?media_type=video/mp4', type='video/mp4'), 'self_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/7a46ff16-422b-4ac8-8302-ae369fa723d6/content?media_type=video/mp4&download=true', type='video/mp4'), 'document_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4', type='video/mp4'), 'document_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4&download=true', type='video/mp4')}, metadata={'end_time': 45.0, 'start_time': 30.0}), ScoredChunk(text='{\"video_description\": \"Here is a detailed description of the video:\\\\n\\\\n**Overall Description:**\\\\n\\\\nThe video features highlights of Lionel Messi playing in what appears to be a World Cup tournament. It consists of two different clips from separate games. The first clip shows Messi scoring a goal and celebrating. The second clip shows Messi as part of the attacking phase for Argentina.\\\\n\\\\n**Clip 1:**\\\\n\\\\n*   **Setting:** A soccer stadium packed with spectators.\\\\n*   **Action:** Messi, wearing the Argentina national team jersey (#10), dribbles the ball past a defender. The defender slips as Messi advances toward the box. Messi scores the goal, and he turns to face the crowd, screaming with joy.\\\\n\\\\n**Clip 2:**\\\\n\\\\n*   **Setting:** A soccer stadium.\\\\n*   **Action:** The second clip shows Argentina in possession of the ball in the attacking third. Messi is among the attacking players positioned around the penalty box. The clip captures the offensive movement.\\\\n\\\\n**Visual Details:**\\\\n\\\\n*   **Color:** Bright and vibrant, capturing the atmosphere of the games.\\\\n*   **Camera Work:** Varied angles, including close-ups of Messi. There are cuts from wide shots showing the field to close-ups of players\\' expressions.\\\\n*   **Graphics:** A logo of FIFA is visible in one clip. The score is displayed on screen in the second clip.\\\\n*   **Teams:** The teams featured are Argentina and Australia. The uniform of Argentina is white with blue vertical stripes. The uniform for Australia is yellow.\\\\n\\\\n**Atmosphere:**\\\\n\\\\nThe video creates an exciting and intense atmosphere, common in high-stakes soccer matches. The first clip showing Messi\\'s goal exudes joy and celebration.\\\\n\", \"audio_transcript\": \"\"}', score=0.07692307692307693, id='6fc5b618-a47d-4f9d-9620-9d7d0fb7947e', index=3, document_id='e80b5e34-ba44-4e88-a627-bc2199e350c2', document_name='messi-goals.mp4', document_metadata={}, links={'self': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6fc5b618-a47d-4f9d-9620-9d7d0fb7947e', type='application/json'), 'self_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6fc5b618-a47d-4f9d-9620-9d7d0fb7947e/content?media_type=text/plain-text', type='text/plain-text'), 'document': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2', type='application/json'), 'document_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=text/plain-text', type='text/plain-text'), 'self_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6fc5b618-a47d-4f9d-9620-9d7d0fb7947e/content?media_type=audio/mpeg', type='audio/mpeg'), 'self_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6fc5b618-a47d-4f9d-9620-9d7d0fb7947e/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'document_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg', type='audio/mpeg'), 'document_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'self_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6fc5b618-a47d-4f9d-9620-9d7d0fb7947e/content?media_type=video/mp4', type='video/mp4'), 'self_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6fc5b618-a47d-4f9d-9620-9d7d0fb7947e/content?media_type=video/mp4&download=true', type='video/mp4'), 'document_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4', type='video/mp4'), 'document_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4&download=true', type='video/mp4')}, metadata={'end_time': 60.0, 'start_time': 45.0}), ScoredChunk(text='{\"video_description\": \"Here is a detailed description of the video:\\\\n\\\\n**Visuals:**\\\\n\\\\nThe video shows Lionel Messi, the Argentine football superstar, in action during a World Cup match, most likely the one played against Croatia. \\\\n\\\\n*   **Opening Scene:** A close-up shot of Messi looking determined and focused. The background is filled with cheering fans and a blurred figure of a player from the opposing team.\\\\n*   **Face-Off:** A moment of tension as Messi and Luka Modri\\\\u0107, a prominent Croatian player, are seen in a side-by-side shot. Both players look serious.\\\\n*   **Penalty Kick:** The most exciting part! Messi is seen taking a penalty kick. The camera captures his run-up, the strike, and the ball hitting the back of the net. The Croatian goalkeeper dives but fails to save it.\\\\n*   **Celebration:** Messi celebrates the goal with his teammates. The joy and excitement on their faces are very apparent. The crowd roars with cheers, and the team is jubilant.\\\\n\\\\n**On-screen Graphics:**\\\\n\\\\n*   The FIFA logo is visible in the top right corner.\\\\n*   Scoreboard: During the goal and the celebrations, the scoreboard in the top left corner is visible. It displays the match score, showing that Argentina (ARG) is leading Croatia (CRO). In particular, the score transitions from 0-0 to 1-0.\\\\n*   Time: The time is also visible, and it shows that the game is near the 33-minute mark.\\\\n\\\\n**Setting:**\\\\n\\\\n*   **Stadium:** The match is played in a packed stadium. The seats are filled with fans from both countries, creating a vibrant atmosphere.\\\\n*   **Football Pitch:** The grass is well-maintained, and the field is marked clearly with the lines of play. Advertisements from various companies are displayed along the sidelines.\\\\n\\\\n**Overall Impression:**\\\\n\\\\nThe video effectively captures a crucial moment in the match \\\\u2013 Messi\\'s successful penalty kick. It shows his determination, the excitement of scoring, and the celebration with his teammates. The combination of close-up shots, the scoreboard, and the crowd reaction provides context and adds to the overall impact of the scene.\", \"audio_transcript\": \"\"}', score=0.07142857142857142, id='4c19512e-df70-464a-aa56-ecfac5a3c72c', index=6, document_id='e80b5e34-ba44-4e88-a627-bc2199e350c2', document_name='messi-goals.mp4', document_metadata={}, links={'self': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/4c19512e-df70-464a-aa56-ecfac5a3c72c', type='application/json'), 'self_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/4c19512e-df70-464a-aa56-ecfac5a3c72c/content?media_type=text/plain-text', type='text/plain-text'), 'document': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2', type='application/json'), 'document_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=text/plain-text', type='text/plain-text'), 'self_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/4c19512e-df70-464a-aa56-ecfac5a3c72c/content?media_type=audio/mpeg', type='audio/mpeg'), 'self_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/4c19512e-df70-464a-aa56-ecfac5a3c72c/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'document_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg', type='audio/mpeg'), 'document_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'self_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/4c19512e-df70-464a-aa56-ecfac5a3c72c/content?media_type=video/mp4', type='video/mp4'), 'self_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/4c19512e-df70-464a-aa56-ecfac5a3c72c/content?media_type=video/mp4&download=true', type='video/mp4'), 'document_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4', type='video/mp4'), 'document_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4&download=true', type='video/mp4')}, metadata={'end_time': 105.0, 'start_time': 90.0}), ScoredChunk(text='{\"video_description\": \"Here is a detailed description of the video:\\\\n\\\\n**General Description:**\\\\n\\\\nThe video shows highlights from the FIFA World Cup Final game between Argentina and France. It features footage of both a penalty kick by Lionel Messi and another important goal during the game.\\\\n\\\\n**Visuals:**\\\\n\\\\n*   **Stadium:** A packed stadium, with vibrant crowds cheering.\\\\n*   **Teams:** Players in the Argentina jersey (white and light blue stripes) and the France jersey (dark blue).\\\\n*   **Penalty Kick (First Part):**\\\\n    *   A goalkeeper in bright orange stands ready in front of the goal.\\\\n    *   A player approaches the penalty spot.\\\\n    *   The player takes the shot, and the goalkeeper dives to the side.\\\\n    *   The ball goes into the net, and the crowd erupts. Players embrace.\\\\n*   **Second Goal Highlight (Second Part):**\\\\n    *   A player kicks the ball at the goal and it is saved.\\\\n    *   The goal is subsequently knocked in by a player on the team in the white and light blue stripes.\\\\n    *   The other players congratulate the player who scored.\\\\n\\\\n**Graphics and Overlays:**\\\\n\\\\n*   **Scoreboard:** The current score is displayed at the top of the screen.\\\\n*   **FIFA Logo:** The FIFA logo is visible in the top right corner.\\\\n*   **Advertising:** The sidelines are lined with ads from sponsors such as Budweiser and crypto.com.\\\\n\\\\n**Overall Impression:**\\\\n\\\\nThis video captures moments of high tension and excitement from the World Cup Final, focusing on specific goals from Argentina.\", \"audio_transcript\": \"\"}', score=0.06666666666666667, id='ac553bf0-09cc-419d-8e85-344ed821be0a', index=7, document_id='e80b5e34-ba44-4e88-a627-bc2199e350c2', document_name='messi-goals.mp4', document_metadata={}, links={'self': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/ac553bf0-09cc-419d-8e85-344ed821be0a', type='application/json'), 'self_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/ac553bf0-09cc-419d-8e85-344ed821be0a/content?media_type=text/plain-text', type='text/plain-text'), 'document': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2', type='application/json'), 'document_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=text/plain-text', type='text/plain-text'), 'self_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/ac553bf0-09cc-419d-8e85-344ed821be0a/content?media_type=audio/mpeg', type='audio/mpeg'), 'self_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/ac553bf0-09cc-419d-8e85-344ed821be0a/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'document_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg', type='audio/mpeg'), 'document_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'self_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/ac553bf0-09cc-419d-8e85-344ed821be0a/content?media_type=video/mp4', type='video/mp4'), 'self_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/ac553bf0-09cc-419d-8e85-344ed821be0a/content?media_type=video/mp4&download=true', type='video/mp4'), 'document_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4', type='video/mp4'), 'document_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4&download=true', type='video/mp4')}, metadata={'end_time': 120.0, 'start_time': 105.0}), ScoredChunk(text='{\"video_description\": \"Okay, here\\'s a detailed description of the video:\\\\n\\\\n**Overall Impression**\\\\nThis video shows a clip of Lionel Messi, the famous Argentinian soccer player, scoring a goal during a FIFA World Cup match. The video showcases his initial celebration, and then a replay of the penalty kick he took to score the goal.\\\\n\\\\n**Detailed Breakdown**\\\\n\\\\n*   **Opening Scene:**\\\\n    *   Messi is wearing the Argentina national team jersey (light blue and white stripes) with the number 10 on his chest and back.\\\\n    *   He\\'s running towards the camera with his arms outstretched in celebration.\\\\n    *   He\\'s looking into the camera with a passionate expression.\\\\n    *   Teammates are also celebrating behind him.\\\\n    *   A packed stadium crowd is visible in the background, cheering wildly. There are a lot of Argentinian flags and colors on display.\\\\n    *   \\\\\"FIFA\\\\\" logo is present in the top right corner.\\\\n\\\\n*   **Goal Replay (Penalty Kick):**\\\\n    *   The video cuts to a wider shot of the soccer field.\\\\n    *   Messi is standing behind the ball, preparing to take a penalty kick.\\\\n    *   Several Dutch players (wearing orange jerseys) are standing inside the penalty box, along with the Argentinian players.\\\\n    *   The scoreboard indicates the match is between the Netherlands (NED) and Argentina (ARG) at the 72:34 minute mark. The score is 0-1 in favor of Argentina.\\\\n    *   Messi takes the penalty kick, shooting the ball towards the left side of the goal.\\\\n    *   The Dutch goalkeeper dives to his right but is unable to save the shot. The ball goes into the back of the net.\\\\n    *   A close-up of the ball hitting the net is shown from a behind-the-goal perspective.\\\\n\\\\n*   **Celebration Recap:**\\\\n    *   The video concludes with a shorter clip that highlights Messi\\'s initial reaction and celebration after the goal.\\\\n    *   Again, Messi is seen running towards the camera and celebrating.\\\\n\\\\n**Other Visual Elements**\\\\n\\\\n*   **Stadium:** The stadium is modern and well-lit, with clear signage.\\\\n*   **Advertisements:** Brand logos are visible on the sidelines of the field.\\\\n\\\\n**Overall, the video is a highlight reel moment from a FIFA World Cup match, capturing the excitement of a goal scored by Lionel Messi.**\", \"audio_transcript\": \"\"}', score=0.0625, id='6e79e197-0ec9-432f-b18f-fc088e2094a5', index=5, document_id='e80b5e34-ba44-4e88-a627-bc2199e350c2', document_name='messi-goals.mp4', document_metadata={}, links={'self': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6e79e197-0ec9-432f-b18f-fc088e2094a5', type='application/json'), 'self_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6e79e197-0ec9-432f-b18f-fc088e2094a5/content?media_type=text/plain-text', type='text/plain-text'), 'document': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2', type='application/json'), 'document_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=text/plain-text', type='text/plain-text'), 'self_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6e79e197-0ec9-432f-b18f-fc088e2094a5/content?media_type=audio/mpeg', type='audio/mpeg'), 'self_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6e79e197-0ec9-432f-b18f-fc088e2094a5/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'document_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg', type='audio/mpeg'), 'document_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'self_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6e79e197-0ec9-432f-b18f-fc088e2094a5/content?media_type=video/mp4', type='video/mp4'), 'self_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/6e79e197-0ec9-432f-b18f-fc088e2094a5/content?media_type=video/mp4&download=true', type='video/mp4'), 'document_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4', type='video/mp4'), 'document_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4&download=true', type='video/mp4')}, metadata={'end_time': 90.0, 'start_time': 75.0}), ScoredChunk(text='{\"video_description\": \"Certainly! Here\\'s a detailed description of the video:\\\\n\\\\n**Content:**\\\\n\\\\nThe video clip captures a moment from a soccer (football) match between Argentina and Mexico. The time is 63 minutes and 33 seconds into the game. The score is 0-0 when Lionel Messi scores a goal for Argentina. We see him kick the ball from outside the penalty area and into the lower left corner of the goal, with the opposing goalkeeper unable to save it.\\\\n\\\\n**Visuals:**\\\\n\\\\n*   The field is a vibrant green with white lines marking boundaries and zones.\\\\n*   Players from both teams are positioned around the field, wearing their respective team uniforms.\\\\n*   The crowd is a large, densely packed mass filling the stadium.\\\\n*   Advertising banners displaying \\\\\"QATAR AIRWAYS\\\\\" and \\\\\"WORLD\\'S BEST AIRLINE\\\\\" surround the perimeter of the field.\\\\n*   There\\'s a clear shot of Messi celebrating the goal.\\\\n\\\\n**Audio:**\\\\n\\\\n*   The video appears to contain crowd noise, with cheering sounds erupting immediately after the goal is scored.\\\\n\\\\n**Overall Impression:**\\\\n\\\\nThe video presents an exciting and pivotal moment during a soccer match, with Lionel Messi scoring for Argentina against Mexico. The stadium is packed, creating a dynamic atmosphere.\", \"audio_transcript\": \"\"}', score=0.058823529411764705, id='2d866a58-6e33-4269-9573-9df6a7714099', index=1, document_id='e80b5e34-ba44-4e88-a627-bc2199e350c2', document_name='messi-goals.mp4', document_metadata={}, links={'self': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/2d866a58-6e33-4269-9573-9df6a7714099', type='application/json'), 'self_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/2d866a58-6e33-4269-9573-9df6a7714099/content?media_type=text/plain-text', type='text/plain-text'), 'document': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2', type='application/json'), 'document_text': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=text/plain-text', type='text/plain-text'), 'self_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/2d866a58-6e33-4269-9573-9df6a7714099/content?media_type=audio/mpeg', type='audio/mpeg'), 'self_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/2d866a58-6e33-4269-9573-9df6a7714099/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'document_audio_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg', type='audio/mpeg'), 'document_audio_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=audio/mpeg&download=true', type='audio/mpeg'), 'self_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/2d866a58-6e33-4269-9573-9df6a7714099/content?media_type=video/mp4', type='video/mp4'), 'self_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/chunks/2d866a58-6e33-4269-9573-9df6a7714099/content?media_type=video/mp4&download=true', type='video/mp4'), 'document_video_stream': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4', type='video/mp4'), 'document_video_download': Link(href='https://api.ragie.ai/documents/e80b5e34-ba44-4e88-a627-bc2199e350c2/content?media_type=video/mp4&download=true', type='video/mp4')}, metadata={'end_time': 30.0, 'start_time': 15.0})]\n"
     ]
    }
   ],
   "source": [
    "response =  ragie.retrievals.retrieve(request={\n",
    "    \"query\": \"Give detailed description of the video with timestamps of the events\"\n",
    "})\n",
    "\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"video_description\": \"Okay, here's a detailed description of the video:\\n\\n**Overall Impression:**\\n\\nThe video focuses on a tense moment from a football (soccer) match. It starts with a game highlight and transitions into promotional content.\\n\\n**Visual Breakdown:**\\n\\n*   **0:00-0:06:** A game clip shows an intense moment near the goal.\\n    *   The camera focuses on the goal area in a packed stadium.\\n    *   The score is ARG 2-2 FRA at 107:55 in the game.\\n    *   A player shoots, the goalkeeper blocks but deflects the ball. Another player then shoots in the rebound attempt.\\n    *   There is audible cheering and excitement from the crowd.\\n\\n*   **0:07-0:15:** Advertisement/Promotional content:\\n    *   The background transitions to a deep blue colour.\\n    *   The following text overlays are displayed in white: \\\"THE ACTION IS ONLY JUST KICKING OFF\\\", \\\"ONLY A\\\", \\\"FIFA\\\", \\\"STREAMING THE FREE STREAMING PLATFORM\\\".\\n    *   Flashes of popular football players are shown briefly: Lionel Messi and Christiano Ronaldo.\\n\\n**Key Observations:**\\n\\n*   The video emphasizes a dramatic moment in football, likely a decisive goal or near-miss, to grab attention.\\n*   The text and graphics suggest an advertisement for a FIFA streaming service.\\n*   The use of Messi and Ronaldo enhances the promotional value.\\n\\nIn essence, the video captures the drama of a football match and promotes the FIFA streaming platform.\", \"audio_transcript\": \"\"}\n",
      "####################################################################################################\n",
      "{\"video_description\": \"Of course! Here's a detailed description of the video you provided:\\n\\n**Overall Impression:**\\n\\nThe video captures a significant moment in a soccer match, specifically a penalty kick taken and scored by Lionel Messi, playing for Argentina. The excitement of the crowd is palpable, and the focus is intensely on Messi and the action around the goal.\\n\\n**Detailed Breakdown:**\\n\\n1.  **Initial Focus:** The video begins with a close-up of Lionel Messi's face. His expression is focused and intense. The camera is at about his eye level.\\n2.  **The Kick:** As the game action begins, the shot widens to show Messi setting up for a penalty kick. The camera provides a wide shot of the field, including the goal, the goalkeeper from Saudi Arabia, and other players from both teams forming lines near the goal.\\n3.  **Goal Scored:** Messi strikes the ball. The goalkeeper dives but is too late. The ball goes into the net. The crowd erupts in cheers.\\n4.  **Celebration:** The camera follows Messi as he celebrates, running towards his teammates. They surround him in a joyful huddle. The Argentine team celebrates their goal together.\\n5.  **Goal Replay:** A quick cut back to the goal area shows a close-up of the goal being scored and the goalkeeper's failed attempt to block it. It highlights the precision and placement of Messi's penalty kick.\\n\\n**Key Elements:**\\n\\n*   **Messi as the Focus:** Lionel Messi is clearly the central figure, with the camera prioritizing his expressions and actions.\\n*   **Crowd Enthusiasm:** The loud cheering and visible excitement in the crowd emphasizes the importance of the moment.\\n*   **The Goal Itself:** The video focuses on both the shot itself and the replay, which highlights the skill of the player and the moment of success.\\n*   **Team Spirit:** The celebration shows the unity and camaraderie of the Argentine team.\\n\\n**In conclusion, the video captures a thrilling moment in a high-stakes soccer match, highlighting Messi's skill and the electrifying atmosphere of the game.**\", \"audio_transcript\": \"\"}\n",
      "####################################################################################################\n",
      "{\"video_description\": \"Here is a detailed description of the video:\\n\\n**Visuals:**\\n\\n*   **Opening Scene:** The video starts with a close-up of several soccer players, wearing the light blue and white jersey of Argentina, in a celebratory hug. They are in the midst of a crowd, suggesting a significant moment in the game. The upper left of the screen shows a game status display: \\\"63:38 ARG 1-0 MEX.\\\" The \\\"FIFA+\\\" logo is in the upper right corner.\\n*   **Celebration Details:** The players are highly animated, with faces of intense excitement and shouts of joy. The camera focuses on the embrace of players.\\n*   **Goal Replay:** A replay follows, displaying the soccer ball entering the net. It shows an Argentinian player, number 10 (Lionel Messi), kicking a low shot towards the goal. The Mexican goalkeeper, in a red and blue uniform, is seen diving in an attempt to block the shot but fails.\\n*   **Wide Shot of the Stadium:** A wider angle shows the goal from behind the net, giving a view of the vast stadium, full of spectators. The lighting is bright and the pitch is green.\\n*   **Focus on the Goalkeeper:** The camera then centers on the Mexican goalkeeper, lying on the ground after the ball has already passed him and made its way into the goal.\\n\\n**Overall Impression:**\\n\\nThe video captures a triumphant moment in a soccer match: Argentina scores a goal against Mexico. It showcases the emotional celebration of the Argentinian team. The replay allows the viewer to see how the goal was scored, highlighting the skill of Lionel Messi and the attempt made by the Mexican goalkeeper. The camera angles switch between close-ups of the players and wider shots of the stadium, immersing the viewer in the atmosphere of the game.\", \"audio_transcript\": \"\"}\n",
      "####################################################################################################\n",
      "{\"video_description\": \"Here is a detailed description of the video:\\n\\n**Overall Description:**\\n\\nThe video features highlights of Lionel Messi playing in what appears to be a World Cup tournament. It consists of two different clips from separate games. The first clip shows Messi scoring a goal and celebrating. The second clip shows Messi as part of the attacking phase for Argentina.\\n\\n**Clip 1:**\\n\\n*   **Setting:** A soccer stadium packed with spectators.\\n*   **Action:** Messi, wearing the Argentina national team jersey (#10), dribbles the ball past a defender. The defender slips as Messi advances toward the box. Messi scores the goal, and he turns to face the crowd, screaming with joy.\\n\\n**Clip 2:**\\n\\n*   **Setting:** A soccer stadium.\\n*   **Action:** The second clip shows Argentina in possession of the ball in the attacking third. Messi is among the attacking players positioned around the penalty box. The clip captures the offensive movement.\\n\\n**Visual Details:**\\n\\n*   **Color:** Bright and vibrant, capturing the atmosphere of the games.\\n*   **Camera Work:** Varied angles, including close-ups of Messi. There are cuts from wide shots showing the field to close-ups of players' expressions.\\n*   **Graphics:** A logo of FIFA is visible in one clip. The score is displayed on screen in the second clip.\\n*   **Teams:** The teams featured are Argentina and Australia. The uniform of Argentina is white with blue vertical stripes. The uniform for Australia is yellow.\\n\\n**Atmosphere:**\\n\\nThe video creates an exciting and intense atmosphere, common in high-stakes soccer matches. The first clip showing Messi's goal exudes joy and celebration.\\n\", \"audio_transcript\": \"\"}\n",
      "####################################################################################################\n",
      "{\"video_description\": \"Here is a detailed description of the video:\\n\\n**Visuals:**\\n\\nThe video shows Lionel Messi, the Argentine football superstar, in action during a World Cup match, most likely the one played against Croatia. \\n\\n*   **Opening Scene:** A close-up shot of Messi looking determined and focused. The background is filled with cheering fans and a blurred figure of a player from the opposing team.\\n*   **Face-Off:** A moment of tension as Messi and Luka Modri\\u0107, a prominent Croatian player, are seen in a side-by-side shot. Both players look serious.\\n*   **Penalty Kick:** The most exciting part! Messi is seen taking a penalty kick. The camera captures his run-up, the strike, and the ball hitting the back of the net. The Croatian goalkeeper dives but fails to save it.\\n*   **Celebration:** Messi celebrates the goal with his teammates. The joy and excitement on their faces are very apparent. The crowd roars with cheers, and the team is jubilant.\\n\\n**On-screen Graphics:**\\n\\n*   The FIFA logo is visible in the top right corner.\\n*   Scoreboard: During the goal and the celebrations, the scoreboard in the top left corner is visible. It displays the match score, showing that Argentina (ARG) is leading Croatia (CRO). In particular, the score transitions from 0-0 to 1-0.\\n*   Time: The time is also visible, and it shows that the game is near the 33-minute mark.\\n\\n**Setting:**\\n\\n*   **Stadium:** The match is played in a packed stadium. The seats are filled with fans from both countries, creating a vibrant atmosphere.\\n*   **Football Pitch:** The grass is well-maintained, and the field is marked clearly with the lines of play. Advertisements from various companies are displayed along the sidelines.\\n\\n**Overall Impression:**\\n\\nThe video effectively captures a crucial moment in the match \\u2013 Messi's successful penalty kick. It shows his determination, the excitement of scoring, and the celebration with his teammates. The combination of close-up shots, the scoreboard, and the crowd reaction provides context and adds to the overall impact of the scene.\", \"audio_transcript\": \"\"}\n",
      "####################################################################################################\n",
      "{\"video_description\": \"Here is a detailed description of the video:\\n\\n**General Description:**\\n\\nThe video shows highlights from the FIFA World Cup Final game between Argentina and France. It features footage of both a penalty kick by Lionel Messi and another important goal during the game.\\n\\n**Visuals:**\\n\\n*   **Stadium:** A packed stadium, with vibrant crowds cheering.\\n*   **Teams:** Players in the Argentina jersey (white and light blue stripes) and the France jersey (dark blue).\\n*   **Penalty Kick (First Part):**\\n    *   A goalkeeper in bright orange stands ready in front of the goal.\\n    *   A player approaches the penalty spot.\\n    *   The player takes the shot, and the goalkeeper dives to the side.\\n    *   The ball goes into the net, and the crowd erupts. Players embrace.\\n*   **Second Goal Highlight (Second Part):**\\n    *   A player kicks the ball at the goal and it is saved.\\n    *   The goal is subsequently knocked in by a player on the team in the white and light blue stripes.\\n    *   The other players congratulate the player who scored.\\n\\n**Graphics and Overlays:**\\n\\n*   **Scoreboard:** The current score is displayed at the top of the screen.\\n*   **FIFA Logo:** The FIFA logo is visible in the top right corner.\\n*   **Advertising:** The sidelines are lined with ads from sponsors such as Budweiser and crypto.com.\\n\\n**Overall Impression:**\\n\\nThis video captures moments of high tension and excitement from the World Cup Final, focusing on specific goals from Argentina.\", \"audio_transcript\": \"\"}\n",
      "####################################################################################################\n",
      "{\"video_description\": \"Okay, here's a detailed description of the video:\\n\\n**Overall Impression**\\nThis video shows a clip of Lionel Messi, the famous Argentinian soccer player, scoring a goal during a FIFA World Cup match. The video showcases his initial celebration, and then a replay of the penalty kick he took to score the goal.\\n\\n**Detailed Breakdown**\\n\\n*   **Opening Scene:**\\n    *   Messi is wearing the Argentina national team jersey (light blue and white stripes) with the number 10 on his chest and back.\\n    *   He's running towards the camera with his arms outstretched in celebration.\\n    *   He's looking into the camera with a passionate expression.\\n    *   Teammates are also celebrating behind him.\\n    *   A packed stadium crowd is visible in the background, cheering wildly. There are a lot of Argentinian flags and colors on display.\\n    *   \\\"FIFA\\\" logo is present in the top right corner.\\n\\n*   **Goal Replay (Penalty Kick):**\\n    *   The video cuts to a wider shot of the soccer field.\\n    *   Messi is standing behind the ball, preparing to take a penalty kick.\\n    *   Several Dutch players (wearing orange jerseys) are standing inside the penalty box, along with the Argentinian players.\\n    *   The scoreboard indicates the match is between the Netherlands (NED) and Argentina (ARG) at the 72:34 minute mark. The score is 0-1 in favor of Argentina.\\n    *   Messi takes the penalty kick, shooting the ball towards the left side of the goal.\\n    *   The Dutch goalkeeper dives to his right but is unable to save the shot. The ball goes into the back of the net.\\n    *   A close-up of the ball hitting the net is shown from a behind-the-goal perspective.\\n\\n*   **Celebration Recap:**\\n    *   The video concludes with a shorter clip that highlights Messi's initial reaction and celebration after the goal.\\n    *   Again, Messi is seen running towards the camera and celebrating.\\n\\n**Other Visual Elements**\\n\\n*   **Stadium:** The stadium is modern and well-lit, with clear signage.\\n*   **Advertisements:** Brand logos are visible on the sidelines of the field.\\n\\n**Overall, the video is a highlight reel moment from a FIFA World Cup match, capturing the excitement of a goal scored by Lionel Messi.**\", \"audio_transcript\": \"\"}\n",
      "####################################################################################################\n",
      "{\"video_description\": \"Certainly! Here's a detailed description of the video:\\n\\n**Content:**\\n\\nThe video clip captures a moment from a soccer (football) match between Argentina and Mexico. The time is 63 minutes and 33 seconds into the game. The score is 0-0 when Lionel Messi scores a goal for Argentina. We see him kick the ball from outside the penalty area and into the lower left corner of the goal, with the opposing goalkeeper unable to save it.\\n\\n**Visuals:**\\n\\n*   The field is a vibrant green with white lines marking boundaries and zones.\\n*   Players from both teams are positioned around the field, wearing their respective team uniforms.\\n*   The crowd is a large, densely packed mass filling the stadium.\\n*   Advertising banners displaying \\\"QATAR AIRWAYS\\\" and \\\"WORLD'S BEST AIRLINE\\\" surround the perimeter of the field.\\n*   There's a clear shot of Messi celebrating the goal.\\n\\n**Audio:**\\n\\n*   The video appears to contain crowd noise, with cheering sounds erupting immediately after the goal is scored.\\n\\n**Overall Impression:**\\n\\nThe video presents an exciting and pivotal moment during a soccer match, with Lionel Messi scoring for Argentina against Mexico. The stadium is packed, creating a dynamic atmosphere.\", \"audio_transcript\": \"\"}\n",
      "####################################################################################################\n"
     ]
    }
   ],
   "source": [
    "content = []\n",
    "for chunk in response.scored_chunks:\n",
    "    print(chunk.text)\n",
    "    print(\"#\"*100)\n",
    "    content.append({\n",
    "            **chunk.document_metadata,\n",
    "            \"text\": chunk.text,\n",
    "            \"document_name\": chunk.document_name,\n",
    "            \"start_time\": chunk.metadata.get(\"start_time\"),\n",
    "            \"end_time\": chunk.metadata.get(\"end_time\")\n",
    "        })"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Video chunk creation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'text': '{\"video_description\": \"Okay, here\\'s a detailed description of the video:\\\\n\\\\n**Overall Impression:**\\\\n\\\\nThe video focuses on a tense moment from a football (soccer) match. It starts with a game highlight and transitions into promotional content.\\\\n\\\\n**Visual Breakdown:**\\\\n\\\\n*   **0:00-0:06:** A game clip shows an intense moment near the goal.\\\\n    *   The camera focuses on the goal area in a packed stadium.\\\\n    *   The score is ARG 2-2 FRA at 107:55 in the game.\\\\n    *   A player shoots, the goalkeeper blocks but deflects the ball. Another player then shoots in the rebound attempt.\\\\n    *   There is audible cheering and excitement from the crowd.\\\\n\\\\n*   **0:07-0:15:** Advertisement/Promotional content:\\\\n    *   The background transitions to a deep blue colour.\\\\n    *   The following text overlays are displayed in white: \\\\\"THE ACTION IS ONLY JUST KICKING OFF\\\\\", \\\\\"ONLY A\\\\\", \\\\\"FIFA\\\\\", \\\\\"STREAMING THE FREE STREAMING PLATFORM\\\\\".\\\\n    *   Flashes of popular football players are shown briefly: Lionel Messi and Christiano Ronaldo.\\\\n\\\\n**Key Observations:**\\\\n\\\\n*   The video emphasizes a dramatic moment in football, likely a decisive goal or near-miss, to grab attention.\\\\n*   The text and graphics suggest an advertisement for a FIFA streaming service.\\\\n*   The use of Messi and Ronaldo enhances the promotional value.\\\\n\\\\nIn essence, the video captures the drama of a football match and promotes the FIFA streaming platform.\", \"audio_transcript\": \"\"}',\n",
       " 'document_name': 'messi-goals.mp4',\n",
       " 'start_time': 120.0,\n",
       " 'end_time': 135.0}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "content[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's see the above video clip to verify the video_description is correct"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MoviePy - Building video videos/goal_clip.mp4.\n",
      "MoviePy - Writing audio in goal_clipTEMP_MPY_wvf_snd.mp3\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                                    \r"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MoviePy - Done.\n",
      "MoviePy - Writing video videos/goal_clip.mp4\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                                         \r"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MoviePy - Done !\n",
      "MoviePy - video ready videos/goal_clip.mp4\n"
     ]
    }
   ],
   "source": [
    "from moviepy import VideoFileClip\n",
    "\n",
    "video = VideoFileClip(\"videos/messi-goals.mp4\")\n",
    "goal_clip = video.subclipped(content[0]['start_time'], content[0]['end_time'])\n",
    "goal_clip.write_videofile(\"videos/goal_clip.mp4\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <video width=\"640\" height=\"480\" controls>\n",
       "        <source src=\"videos\\goal_clip.mp4\" type=\"video/mp4\">\n",
       "        Your browser does not support the video tag.\n",
       "    </video>\n",
       "    "
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from IPython.display import HTML\n",
    "from pathlib import Path\n",
    "\n",
    "# View the created video chunk\n",
    "video_path = Path('videos/goal_clip.mp4')\n",
    "if video_path.exists():\n",
    "    video_html = f'''\n",
    "    <video width=\"640\" height=\"480\" controls>\n",
    "        <source src=\"{video_path}\" type=\"video/mp4\">\n",
    "        Your browser does not support the video tag.\n",
    "    </video>\n",
    "    '''\n",
    "    display(HTML(video_html))\n",
    "else:\n",
    "    print(\"Video file not found!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
